﻿using LuckyShell.ShellValues;

namespace LuckyShell.ShellOrders;

public class WhileOrder(ShellValue expr, BlockOrder blockOrder) : ShellOrder
{
    private ShellValue Expr { get; set; } = expr;
    private BlockOrder BlockOrder { get; set; } = blockOrder;

    public void Run(ref VariateManager manager)
    {
        manager.AddChildren();
        while (true)
        {
            var varBool = (bool)Expr.GetValue(ref manager);

            if (varBool)
                BlockOrder.Run(ref manager);
            else
            {
                manager.RemoveChildren();
                return;
            }
        }
    }
}